<template>
  <div class="index">
    <div class="left">
      <h2>悦宾阁酒店综合平台</h2>
      <el-menu
        @select="selectMenuItem"
        :default-active="activeIndex"
        router
        active-text-color="#ffd04b"
        background-color="#142334"
        class="el-menu-vertical-demo"
        text-color="#fff">
        <el-sub-menu index="1">
          <template #title>
            <el-icon><User /></el-icon>
            <span>账户管理</span>
          </template>
          <el-menu-item index="/role">酒店管理</el-menu-item>
          <el-menu-item index="/user">用户管理</el-menu-item>
          <el-menu-item index="/employ">员工管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="2">
          <template #title>
            <el-icon><DishDot /></el-icon>
            <span>客房管理</span>
          </template>
          <el-menu-item index="/roomtype">房型管理</el-menu-item>
          <el-menu-item index="/room">房间管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="3">
          <template #title>
            <el-icon><Camera /></el-icon>
            <span>客户管理</span>
          </template>
          <el-menu-item index="/livein">入住管理</el-menu-item>
          <el-menu-item index="/order">客户订单</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="4">
          <template #title>
            <el-icon><Setting /></el-icon>
            <span>系统管理</span>
          </template>
          <el-menu-item index="/menu">菜单管理</el-menu-item>
          <el-menu-item index="/dictionary">字典管理</el-menu-item>
        </el-sub-menu>
         <el-sub-menu index="5">
          <template #title>
            <el-icon><Setting /></el-icon>
            <span>客服服务</span>
          </template>
          <el-menu-item index="/messageprocess">消息处理</el-menu-item>
        </el-sub-menu>

      </el-menu>
    </div>
    <div class="right">
      <div class="top">
        <el-menu
          @select="selectMenuItem"
          router
          :ellipsis="false"
          :default-active="activeIndex"
          mode="horizontal"
          background-color="#142334"
          text-color="#fff"
          active-text-color="#ffd04b">
          <el-menu-item index="/index">
            <el-icon><HomeFilled /></el-icon>
            首页
          </el-menu-item>
          <el-menu-item index="/mail">
            <el-icon><Message /></el-icon>
            邮件
          </el-menu-item>
          <el-menu-item index="/message">
            <el-icon><ChatDotSquare /></el-icon>
            消息
          </el-menu-item>
          <el-sub-menu index="admin">
            <template #title>
              <el-icon><Avatar /></el-icon>
              {{userName}}
            </template>
            <el-menu-item index="/mine">个人中心</el-menu-item>
            <el-menu-item index="/setpwd">修改密码</el-menu-item>
            <el-menu-item index="" @click="exit">退出系统</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
      <div class="content">
        <router-view ></router-view>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import {useRoute, useRouter} from 'vue-router'
import {User,DishDot,Setting,Camera,HomeFilled,Message,ChatDotSquare,Avatar} from '@element-plus/icons-vue'
import userUser from '../stores/user.js'
import { ElMessageBox } from 'element-plus'

 let userStore = userUser()
 let router = useRouter()
// onMounted(()=>{
//   if(!userStore.user.loginId){
//     router.push('/')
//   }

const userName = ref('');
userName.value=userStore.user.username

const activeIndex = ref('/index'); // 或者其他默认激活的菜单项索引

const selectMenuItem = async (routePath: string) => {
  try {
    await router.push(routePath);
  } catch (error) {
    // 处理错误，例如通过显示一个错误消息
    console.error('Failed to navigate to route:', routePath, error);
  }
};

// 退出系统
let exit = ()=>{
  ElMessageBox.confirm(
    '确定退出系统吗？',
    '系统提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
  .then(() => {
      userStore.clearUser()
      router.push('/')
  })
  .catch(() => {})
}

</script>

<style scoped lang="scss">
.index{
  width: 100vw;
  height: 90vh;
  display: flex;
  .left{
    width: 200px;
    background-color: #142334;
    color: white;
    .el-menu{
      border-right: none;
    }
    h2{
      font-size: 20px;
      font-family: bing;
      text-align: center;
      height: 60px;
      line-height: 60px;
    }
  }
  .right{
    flex: 1;
    display: flex;
    flex-direction: column;
    .top{
      height: 60px;
      background-color: #142334;
      color: white;
      display: flex;
      justify-content: flex-end;
      .el-menu{
        border-bottom: none;
      }
    }
    .content{
      flex: 1;
      padding: 5px;
    }
  }
}
</style>
